package com.qxf.sell.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qxf.sell.model.UserInfo;
import com.qxf.sell.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qxf
 * @since 2021-04-30
 */
@RestController
@RequestMapping("/user-info")
public class UserInfoController {

    @Autowired
    public IUserInfoService userInfoService;

    @PostMapping("/getUser")
    public List<UserInfo> getUser() {
        return userInfoService.findAllUser();
    }

    @PostMapping("/getUserByPage")
    public IPage<UserInfo> getUserByPage() {
        IPage<UserInfo> page = new Page<>(1, 2);
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
        return userInfoService.getUserByPage(page, wrapper);
    }

    /**
     * 注册
     */
    @PostMapping("/register")
    public boolean register(@RequestParam(value = "name") String name, @RequestParam("age") int age, @RequestParam("password") String password) {
        int insertNum = userInfoService.register(name, age, password);
        return insertNum > 0;
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    public boolean login(@RequestParam("name") String name, @RequestParam("password") String password) {
        return userInfoService.login(name, password);
    }
}

